#include "stdafx.h"
#include "MainPlugin.h"
#include "tray\traysrvplugin.h"
#include "DownloadTray.h"


CMainPlugin::CMainPlugin(void)
{
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
}


CMainPlugin::~CMainPlugin(void)
{

}

HRESULT CMainPlugin::OnAfterInit(void*)
{
	CSkinManager::Init(GetModuleInstance());
	CPaintManagerUI::SetInstance(GetPorcessInstance());
	//CPaintManagerUI::SetResourcePath(_T("skin"));
	//CPaintManagerUI::SetResourceZip(_T("ListRes.zip"));

 	RASSERT(m_pRot , E_FAIL);
 	UTIL::com_ptr<IMSBase> pSignalApp;
 	m_pRot->GetObject(CLSID_SignalApp , re_uuidof(IMSBase) , (void**)&pSignalApp);
 	RASSERT(pSignalApp , E_FAIL);
 	RFAILED(m_pSignalApp.Connect(pSignalApp , UTIL::com_ptr<IMSBase>(this)));

	m_pRot->GetObject(GUID_FrameWindow,re_uuidof(IFrameWindow),(void**)&m_pFrameWindow);
	return S_OK;
}

HRESULT CMainPlugin::OnBeforeUnint()
{
	CSkinManager::UnInit();
	m_pSignalApp.DisConnect();
	SAFE_RLEASE(m_pFrameWindow);
	return S_OK;
}

HRESULT CMainPlugin::OnAfterStart()
{
	return S_OK;
}

HRESULT CMainPlugin::OnBeforeStop()
{
	return S_OK;
}

STDMETHODIMP CMainPlugin::NotifyExit(bool* bExit /*= NULL*/)
{
	PostQuitMessage(IDCANCEL);
	if (bExit)
	{
		bExit = FALSE;
	}
	Stop();
	return S_OK;
}

STDMETHODIMP CMainPlugin::OnSingleAppMsg(IXMLTree3* lpArgXml , BOOL& bHandle)
{
	RASSERT(m_pFrameWindow,E_FAIL);
	HWND hWnd = m_pFrameWindow->GetFrameHWND();
	SetForegroundWindow(hWnd);
 	LONG_PTR longPtr = GetWindowLongPtr(hWnd,GWL_STYLE);
	PostMessage(hWnd , WM_SYSCOMMAND , longPtr & WS_MAXIMIZE ? SC_MAXIMIZE:SC_RESTORE,0);
 	ShowWindow(hWnd, SW_SHOW);

	return S_OK;
}

HRESULT CMainPlugin::CreateUiFrame()
{
	

	return S_OK;
}

HRESULT CMainPlugin::DistoryUiFrame()
{

	return S_OK;
}

HRESULT CMainPlugin::OnTranslateSource(RSMSGID msgid,IMsBuffer* pBuf)
{
	OutputDebugString(_T("CMainPlugin::OnTranslateSource\r\n"));
	return S_OK;
}

HRESULT CMainPlugin::OnDefaultMsg(RSMSGID msgid,IMsBuffer* pBuf)
{
	OutputDebugString(_T("CMainPlugin::OnDefaultMsg\r\n"));
	return S_OK;
}